import java.util.*;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import java.util.Collection;
/**
*This is the Encapsulation test class. It is use just to set and get the value.
*/
public class EncapsulationTest implements Comparator{

	private String name;
	
	private String idNum;

	private String addr;

	private int age;

	private int m1;

	private int m2;

	private int m3;

	private int totle;

	private  float avg;

	private List<String> studinfo=new ArrayList<String>();
	
	public EncapsulationTest(String name,String  idNum,String addr,int age){
		this.name=name;
		this. idNum= idNum;
		this.addr=addr;
		this.age=age;

		studinfo.add(this.name);
		studinfo.add(this.idNum);
		studinfo.add(this.addr);
		studinfo.add(""+this.avg);
	}

	public EncapsulationTest(int m1,int m2,int m3){
		this.m1=m1;
		this.m2=m2;
		this.m3=m3;
		
	}
	public EncapsulationTest(){
		
	}

	//Geting and setting the age
	public int getAge()
	{
		return age;
   	}
	
	public void setAge( int newAge)
	{	
	      age = newAge;
   	}
	//Geting and setting the marks 1
	public int getM1()
	{
		return m1;
   	}

	public void setM1( int newM1)
	{	
	      m1 = newM1;
   	}
	//Geting and setting the marks 2
	public int getM2()
	{
		return m2;
   	}
	public void setM2( int newM2)
	{	
	      m2 = newM2;
   	}
	//Geting and setting the marks 2
	public int getM3()
	{
		return m3;
   	}
	public void setM3( int newM3)
	{	
	      m3 = newM3;
   	}
	//Geting and setting the name
        public String getName()
	{
	      return name;
        }
	public void setName(String newName)
	{
	      name = newName;	
   	}
	//Geting and setting the address
	public String getAddr()
	{
	      return addr;
        }
	public void setAddr(String newAddr)
	{
	      addr = newAddr;	
   	}
	//Geting and setting the id
        public String getIdNum()
	{
	      	return idNum;
        }
   	public void setIdNum( String newId)
	{
	      idNum = newId;	
   	}
	//Calculating the avg parameter
	public float calculateAvg(){
		totle=m1+m2+m3;
		avg=totle/3;
		return avg;
		
	}


	/*
	*Comparator method 
	*/
	public int compare(Object obj1, Object obj2){
	
		EncapsulationTest stud1=(EncapsulationTest)obj1;
		EncapsulationTest stud2=(EncapsulationTest)obj2;

		if((stud1.name==stud2.name)&& (stud1.addr==stud2.addr))
			return 1;
		else
			return 0;
		
	}

	/**
	* Equal method
	*In this method we compaire only the name attribute
	*/
	@Override
	public boolean equals(Object obj){ 

		if(obj == null) {
			return false;
		}
		if(obj.getClass() != getClass()){
			return false;
		}

		EncapsulationTest encapTest = (EncapsulationTest)obj;
		if(this.name == encapTest.name){
			return true;
		}
		return false;
	}

	/*hashcode method
	* In this method we find the hashcode of name parameter
	*/
	@Override
	public int hashCode(){
		int sum=0;
		for(int i=0;i<this.name.length();i++){
			sum+=name.charAt(i);
		}
	return sum;
		
	}

	void printStudentInfo(){
		System.out.println("*************  Student Extra Information ***********");
		System.out.println("Student Name : " + this.name);
        	System.out.println("Student Age : "+ this.age);
		System.out.println("Student Adress : "+ this.addr);
        	System.out.println("Student Id Number is : "+this.idNum );
		System.out.println("**************************************************");
	}
}





